package com.qk.management.controller;

import com.qk.dto.course.CourseQueryDTO;
import com.qk.result.PageResult;
import com.qk.result.Result;
import com.qk.entity.Course;
import com.qk.management.service.CourseService;
import com.qk.vo.course.CourseQueryVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;
/**
 * @Author:zhengbowen
 * @Date: 2025/10/06 16:19
 * @Description:课程管理控制器
 */
@RestController
@Slf4j
@RequestMapping("/courses")
@RequiredArgsConstructor
public class CourseController {

    private final CourseService courseService;

    @DeleteMapping("/{id}")
    public Result deleteCourse(@PathVariable Integer id) {
        courseService.deleteCourse(id);
        return Result.success();
    }

    @PostMapping()
    public Result insertCourse(@RequestBody Course course) {
        courseService.insertCourse(course);
        return Result.success();
    }

    @PutMapping( "")
    public Result updateCourse(@RequestBody Course course) {
        courseService.updateCourse(course);
        return Result.success();
    }


    @GetMapping("")
    public Result selectCoursesByPage(CourseQueryDTO courseQueryDTO) {
        PageResult<CourseQueryVO> pageResult = courseService.selectCoursesByPage(courseQueryDTO);
        return Result.success(pageResult);
    }
    @GetMapping("{id}")
    public Result selectCourseById(@PathVariable Integer id) {
        Course course = courseService.selectCourseById(id);
        return Result.success(course);
    }
    @GetMapping("/subject/{subject}")
    public Result selectCoursesBySubject(@PathVariable Integer subject) {
        List<Course> pageInfo  = courseService.selectCoursesBySubject(subject);
        return Result.success(pageInfo);
    }
    @GetMapping("/list")
    public Result selectCourses() {
        List<Course> pageInfo  = courseService.selectCourses();
        return Result.success(pageInfo);
    }
}
